import random


def count_sort(arr_len):
    arr = []
    range_num = 100

    #建立一个原数组arr
    for i in range(arr_len):
        arr.append(random.randint(0, range_num))
    print(arr)

    #建立一个数值范围作为下标范围的新数组
    count = [0] * range_num
    i = 0

    while i < arr_len:  # 统计原数组里，每个数出现的次数，比如13出现了1次，那么count[13]=1
        count[arr[i]] += 1
        i += 1

    k = 0
    for i in range(range_num):  # 统计好了之后，回填到原数组arr中
        j = 0
        while j < count[i]:
            arr[k] = i
            k += 1
            j += 1
    print(arr)


if __name__ == '__main__':
    count_sort(10)
